<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *项目管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('start','off');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择信息！','error');
	}
}
$return['sex']=$this->sex;
$return['status']=$this->gong_status;
if($_RQ['op']=='list'){
	$params=array('merchid'=>$merchid);
	$params['uniacid']=$_SESSION['uniacid'];
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}
	if($_SESSION['os']!='windows'){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=intval($_RQ['mid']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_51job_gong',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('member')->member_show($item['memberid']);
			$item['sex']=$item['member']['sex'];
			$job=pdo_get('jy_51job_job',array('id'=>$item['jobid'],'uniacid'=>$_SESSION['uniacid']));
			$item['pay']=$job['pay'];
			$item['city']=$job['city'];
			$item['onlinetime']=json_decode($job['onlinetime'],true);
			$item['images']=json_decode($job['images'],true);
			$item['jobinfo']=json_decode($item['jobinfo'],true);
			$item['isme']=$item['mid']==$_SESSION['uid'] ? 1 :0;
			$item['baotypetitle']=$this->job_paytype2[$job['paytype']].'结('.$this->job_baotype[$job['baotype']].'版)';
			$item['merchname']=pdo_getcolumn('jy_51job_merch',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['merchid']),'title');
			$item['statustitle']=$this->gong_status[$item['status']];
			$item['typetitle']=$this->job_type[$item['jobinfo']['type']];
			$item['paytypetitle']=$this->job_paytype[$item['jobinfo']['paytype']];
			$item['createtime']=date('Y-m-d H:i:s', $item['createtime']);
			$item['lat_lng']=$item['lat_lng']?json_decode($item['lat_lng'],true):'';
			$item['pcd']=$item['pcd']?json_decode($item['pcd'],true):array('city'=>'');
			$item['addressinfo']=array('address'=>$item['address'],'lat_lng'=>$item['lat_lng']);
			$item['signlog']=pdo_get('jy_51job_signlog',array('uniacid'=>$_SESSION['uniacid'],'gongid'=>$item['id']),'','createtime desc');
			$item['signlog']['uptime2']=date('Y-m-d H:i:s', $item['uptime']);
			$item['signlog']['starttime2']=$item['starttime']?date('Y-m-d H:i:s', $item['starttime']):'';
			$item['signlog']['endtime2']=$item['endtime']?date('Y-m-d H:i:s', $item['endtime']):'';
			$item['maplog']=pdo_get('jy_51job_maplog',array('uniacid'=>$_SESSION['uniacid'],'gongid'=>$item['id']),'','createtime desc');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'人才人才'),
		),
		'list'=>array('data'=>'list','tip'=>'<red>[温馨提示]：这里显示人才人才情况，包括（实习，在职，离职）</red>','edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'人才信息','type'=>'member'),
			array('name'=>'sex','title'=>'性别','type'=>'radio','options'=>'sex'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'fee','title'=>'薪资','type'=>'string'),
			array('name'=>'day','title'=>'入职日期','type'=>'string'),
			array('name'=>'pcd','title'=>'上班地','type'=>'pcd'),
			array('name'=>'address','title'=>'上班详细地址','type'=>'string'),
			array('name'=>'jobinfo.title','title'=>'工作名称','type'=>'string'),
			array('name'=>'uptime','title'=>'最近打卡时间','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
		),'action'=>array(
			array('title'=>'签协议','type'=>'modal','op'=>'xieyi','show'=>array('isxieyi'=>0)),
			array('title'=>'签合同','type'=>'modal','op'=>'hetong','show'=>array('ishetong'=>0,'ishetonguser'=>1,'isxieyi'=>1)),
			array('title'=>'办入职','type'=>'href','op'=>'status2','show'=>array('status'=>array(1))),
			array('title'=>'岗位设置','type'=>'href','op'=>'upinfo','show'=>array('status'=>array(2))),
			array('title'=>'办离职','type'=>'href','op'=>'status3','show'=>array('status'=>array(2))),
		)),
		'search'=>array(
			array('name'=>'mid','width'=>15,'title'=>'人才人','type'=>'choose','action'=>'jy_51job/get_member/'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'status'),
		)
	);
	$return['sex']=$this->sex;
	$return['pay']=$this->xinzhis;
	if($_SESSION['os']=='windows'){
		$return['htmls']=$htmls;
	}
	exi($return);
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的项目！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_51job_job',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	if(isset($post['ishot'])){
		$basic=$this->plugin_setting('basic');
		$topdays=intval($basic['topdays'])?:7;
		$topendtime=TIMESTAMP+$topdays*24*3600;
		pdo_update('jy_51job_job',array('ishot'=>intval($post['ishot']),'topendtime'=>$topendtime),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='xieyi'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$isxieyi=intval($post['isxieyi']);
		if($isxieyi && $post['isxieyiuser'] && $post['ishetong'] && $post['ishetonguser']){
			$status=1;
		}
		pdo_update('jy_51job_gong',array('isxieyi'=>$isxieyi,'status'=>$status),array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'id'=>intval($post['id'])));
		exi('处理成功！','','/merch.gong/list/');
	}
	$item=pdo_get('jy_51job_gong',array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'id'=>intval($_RQ['id'])));
	if(!$item){
		exi('入职信息不存在！','error');
	}
	$xieyitpl=pdo_get('jy_51job_xieyitpl',array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'status'=>1));
	$item['xieyi']=$xieyitpl['content'];
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'签协议',
		'edit'=>array(
			array('name'=>'xieyi','title'=>'协议内容','type'=>'richtextlook'),
			array('name'=>'isxieyi','title'=>'是否签署','type'=>'radio','options'=>'qian_status'),
		),
	);
	$return['qian_status']=$this->qian_status;
	exi($return);
}
if($_RQ['op']=='hetong'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$ishetong=intval($post['ishetong']);
		if($ishetong==1){
			$this->model('job')->uphetong($post,$ishetong);
		}
		if($ishetong && $post['isxieyiuser'] && $post['ishetong'] && $post['ishetonguser']){
			$status=1;
		}
		pdo_update('jy_51job_gong',array('ishetong'=>$ishetong,'status'=>$status),array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'id'=>intval($post['id'])));
		exi('处理成功！','','/merch.gong/list/');
	}
	$item=pdo_get('jy_51job_gong',array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'id'=>intval($_RQ['id'])));
	if(!$item){
		exi('入职信息不存在！','error');
	}
	$hetongtpl=pdo_get('jy_51job_hetongtpl',array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'status'=>1));
	$item['images']=json_decode($hetongtpl['images'],true);
	$item['hetplid']=$hetongtpl['id'];
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'签合同',
		'edit'=>array(
			array('name'=>'images','title'=>'合同内容','type'=>'imgs_show'),
			array('name'=>'ishetong','title'=>'是否签署','type'=>'radio','options'=>'qian_status'),
		),
	);
	$return['qian_status']=$this->qian_status;
	exi($return);
}
if($_RQ['op']=='status2'){
	if($_RQ['postdata']){
		$post=get_postdata();
		pdo_update('jy_51job_gong',array('day'=>$post['day'],'status'=>2),array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'id'=>intval($post['id'])));
		exi('处理成功！','','/merch.gong/list/');
	}
	$item=pdo_get('jy_51job_gong',array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'id'=>intval($_RQ['id'])));
	if(!$item){
		exi('入职信息不存在！','error');
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'岗位设置',
		'edit'=>array(
			array('name'=>'day','title'=>'入职日期','type'=>'time','time_type'=>'day'),
		),
	);
	$return['qian_status']=$this->qian_status;
	exi($return);
}
if($_RQ['op']=='status3'){
	if($_RQ['postdata']){
		$post=get_postdata();
		pdo_update('jy_51job_gong',array('endday'=>$post['endday'],'status'=>3),array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'id'=>intval($post['id'])));
		pdo_update('jy_51job_job_log',array('status'=>3),array('id'=>$post['joblogid'],'uniacid'=>$_SESSION['uniacid']));
		exi('处理成功！','','/merch.gong/list/');
	}
	$item=pdo_get('jy_51job_gong',array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'id'=>intval($_RQ['id'])));
	if(!$item){
		exi('员工信息不存在！','error');
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'岗位设置',
		'edit'=>array(
			array('name'=>'endday','title'=>'离职日期','type'=>'time','time_type'=>'day'),
		),
	);
	$return['qian_status']=$this->qian_status;
	exi($return);
}
if($_RQ['op']=='upinfo'){
	if($_RQ['postdata']){
		$post=get_postdata();
		if($post['addressinfo']){
			$post['address']=$post['addressinfo']['address'];
			$post['lat_lng']=$post['addressinfo']['lat_lng'];
		}
		pdo_update('jy_51job_gong',array('pcd'=>ijson_encode($post['pcd']),'lat_lng'=>ijson_encode($post['lat_lng']),'address'=>$post['address']),array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'id'=>intval($post['id'])));
		exi('处理成功！','','/merch.gong/list/');
	}
	$item=pdo_get('jy_51job_gong',array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'id'=>intval($_RQ['id'])));
	if(!$item){
		exi('入职信息不存在！','error');
	}
	$item['pcd']=json_decode($item['pcd'],true);
	$item['lat_lng']=json_decode($item['lat_lng'],true);
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'岗位设置',
		'edit'=>array(
			array('name'=>'pcd','title'=>'打卡地','type'=>'pcd'),
			array('name'=>'address','title'=>'打卡详细地址','type'=>'string'),
			array('name'=>'lat_lng','title'=>'打卡坐标','type'=>'lat_lng'),
		),
	);
	$return['qian_status']=$this->qian_status;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_51job_gong',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}